package com.automannn.atm_back.modules.codeGenerator.controller;

import com.automannn.atm_back.common.api.vo.Result;
import com.automannn.atm_back.modules.codeGenerator.entity.ColumnConfigEntity;
import com.automannn.atm_back.modules.codeGenerator.entity.TypeMapperEntity;
import com.automannn.atm_back.modules.codeGenerator.service.TypeMapperEntityService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * (GeneratorTypeMapper)表控制层
 *
 * @author chenkaihai
 * @since 2020-07-12 17:06:20
 */
@RestController
@RequestMapping("codeGenerator/generatorTypeMapper")
@Valid
public class TypeMapperEntityController {
    /**
     * 服务对象
     */
    @Resource
    private TypeMapperEntityService typeMapperEntityService;


    /**
     * 分页查询所有数据
     */
    @GetMapping("list")
    public Result selectAll(Page<TypeMapperEntity> page, TypeMapperEntity typeMapperEntity) {
        Result result = new Result();
        IPage<TypeMapperEntity> pageList = typeMapperEntityService.queryAll(page, typeMapperEntity);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result selectOne(@PathVariable String id) {
        return Result.ok(typeMapperEntityService.queryOne(id));
    }

    /**
     * 新增数据
     */
    @PostMapping("add")
    public Result insert(@RequestBody TypeMapperEntity typeMapperEntity) {
        this.typeMapperEntityService.insert(typeMapperEntity);
        return Result.ok("新增成功!");
    }

    /**
     * 修改数据
     */
    @PutMapping("edit")
    public Result update(@RequestBody TypeMapperEntity typeMapperEntity) {
        this.typeMapperEntityService.update(typeMapperEntity);
        return Result.ok("修改成功!");
    }

    /**
     * 新增数据
     *
     * @param typeMapperEntityList 实体对象
     * @return 新增结果
     */
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody List<TypeMapperEntity> typeMapperEntityList) {
        this.typeMapperEntityService.saveOrUpdate(typeMapperEntityList);
        return Result.ok("保存成功!");
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public Result delete(String id) {
        this.typeMapperEntityService.deleteById(id);
        return Result.ok("删除成功!");
    }

    @DeleteMapping("deleteBatch")
    public Result deleteBatch(String ids) {
        this.typeMapperEntityService.deleteBatchByIds(ids);
        return Result.ok("批量删除成功!");
    }

}
